﻿@using PagedList.Mvc
@model PagedList.IPagedList<CubicFWNet.Data.ViewModal.InvoiceView>
@{
    //ViewBag.Title = "原料成本核算";
    var number = ViewBag.Number;
    var beginTime = ViewBag.beginTime;
    var endTime = ViewBag.endTime;
}
<section class="content-header">
    <h1>
        派车单查询
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("SendCarQuery", "Transport")">派车单查询</a></li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="box box-solid">
                <div class="box-nav clearfix">
                    <div class="col-sm-12 col-md-9">
                        <button type="button" class="btn btn-primary" onclick="query();" title="查询"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
                        <button type="button" class="btn btn-primary" onclick="print();" title="打印">打印</button>
                        <button type="button" class="btn btn-primary" onclick="printComplete();" title="打印完毕">打印完毕</button>
                        <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table class="footable table table-stripped table-bordered table-hover" id="footable">
                        <thead>
                            <tr>
                                <th data-sort-ignore="true">
                                </th>
                                <th data-sort-ignore="true">
                                    申请人
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    日期
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    送货要求
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    内容
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    单号
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    货物总值
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    客户名称
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    部门类型
                                </th>
                                <th data-sort-ignore="true">
                                    状态
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (null != Model)
                            {
                                foreach (var item in Model)
                                {
                                    <tr>
                                        <td><input type="checkbox" class="minimal pull-right minimalBox" date-subid="@item.SubId"></td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.CreatorName)
                                        </td>
                                        <td>
                                            @item.ApplyTime.ToString("yyyy-MM-dd")
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.DliveryDemand)
                                        </td>
                                        <td>
                                            @if (item.SendType == 0)
                                            {
                                                @Html.Raw("发货")
                                            }
                                            else if (item.SendType == 1)
                                            {
                                                @Html.Raw("取货")
                                            }
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Number)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Worth)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.TakeCompany)
                                        </td>
                                        <td>
                                            @if (item.SendCardType == 0)
                                            {
                                                @Html.Raw("售后部")
                                            }
                                            else if (item.SendCardType == 1)
                                            {
                                                @Html.Raw("采购部")
                                            }
                                        </td>
                                        <td>
                                            @if (item.Status == 0)
                                            {
                                                @Html.Raw("未打印")
                                            }
                                            else if (item.Status == 1)
                                            {
                                                @Html.Raw("已打印")
                                            }
                                            @*<a class="btn bg-blue btn-xs" href="@Url.Action("DeliverGoods", "Transport", new {inId = item.Id})">打印</a>*@
                                        </td>
                                        
                                    </tr>
                                }
                            }
                        </tbody>
                        @if (null != Model)
                        {
                            <tfoot>
                                <tr>
                                    <td colspan="9">
                                        @*<ul class="pagination pull-right"></ul>*@
                                        每页 @Model.PageSize 条记录，共 @Model.PageCount 页，当前第 @Model.PageNumber 页
                                        @Html.PagedListPager(Model, page => Url.Action("SendCarQuery", new { page, number, beginTime, endTime }))
                                    </td>
                                </tr>
                            </tfoot>
                        }
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<!--查询对话框-->
<div class="modal" id="queryDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">查询</h4>
            </div>
            <form class="form-horizontal" id="frmquery" action="@Url.Action("SendCarQuery", "Transport")" method="post">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 发货单编号 </label>
                        <div class="col-sm-8">
                            @*<input type="hidden" class="form-control formId" id="Id" name="Id" />*@
                            <input type="text" class="form-control" id="number" name="number" value="@number" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 开始时间 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control Timedatepicker" id="beginTime" name="beginTime" value="@beginTime" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 结束时间 </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control Timedatepicker" id="endTime" name="endTime" value="@endTime" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>
    </div>
</div>
@section Scripts {
    <script>
        //window.location.reload();
        var jsonData = { WebCheckbox: {} };
        jsonData.WebCheckbox.Ids = [];
        $(document).ready(function () {
            $('#footable').footable();
            //日期控件
            $(".Timedatepicker").datepicker({
                autoclose: true,
                language: 'zh', //汉化
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                minView: "month"//选择日期后，不会再跳转去选择时分秒
            });
        });

        $("#footable").find("input[type='checkbox']").each(function (i, e) {
            if (jsonData.WebCheckbox.Ids.indexOf($(e).attr("data-proId")) > -1) {
                $(e).iCheck('check');
            } else {
                $(e).iCheck('uncheck');
            }
        });


        $('input[type="checkbox"].minimal,input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue'
        });

        //多选选中
        $('input[type="checkbox"].minimalBox').on('ifClicked', function (event) {
            var subId = $(this).attr("date-subid");
            //现在判断时若是选中的，点击完了就变成了未选中了
            if ($(this).is(":checked")) {
                jsonData.WebCheckbox.Ids.splice($.inArray(subId, jsonData.WebCheckbox.Ids), 1); //删除对应的Id'
            } else //这里判断是没选中，点击完了就变成选中了
            {
                if (jsonData.WebCheckbox.Ids.indexOf(subId) <= -1) {
                    jsonData.WebCheckbox.Ids.push(subId); //添加对应的Id'
                } else {
                    $.modalAlert("不可重复", "warning");
                    return false;
                }
            }
            console.log(jsonData.WebCheckbox.Ids);
        });

        function print() {
            if (jsonData.WebCheckbox.Ids.length <= 0) {
                $.modalAlert("请勾选再打印", "warning");
                return false;
            }
            window.location.href = "/Transport/SendCarPrint?strids=" + jsonData.WebCheckbox.Ids;
        }

        function printComplete() {
            if (jsonData.WebCheckbox.Ids.length <= 0) {
                $.modalAlert("请勾选再点击完成", "warning");
                return false;
            }
            $.ajax({
                url: "/Transport/SendCarPrintComplete",
                type: "post",
                data: {
                    strids: jsonData.WebCheckbox.Ids
                },
                success: function (data) {
                    if (data && JSON.parse(data)) {
                        var d = JSON.parse(data);
                        if (d.code == 200) {
                            $.modalAlert("更新完成", "success");

                        } else {
                            $.modalAlert("错误", "warning");
                        }
                    } else {
                        $.modalAlert("错误", "warning");
                    }
                    window.location.reload();
                },
                error: function (xhr, err, state) {
                }
            });
        }


        function query() {
            //$("#frmedit").formInit();
            $('#queryDlg').modal();
        }

    </script>
}